package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CustomerTraceHistory;
import cn.wolfcode.crm.qo.QueryObject;
import cn.wolfcode.crm.service.ICustomerTraceHistoryService;
import cn.wolfcode.crm.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/customerTraceHistory")
public class CustomerTraceHistoryController {

    @Autowired
    private ICustomerTraceHistoryService customerTraceHistoryService;

    //查询所有
    @RequestMapping("/list")
    @RequiresPermissions(value = {"customerTraceHistory:list", "部门列表"},logical = Logical.OR)
    public String list(Model model,@ModelAttribute("qo")QueryObject qo){

        PageInfo pageInfo = customerTraceHistoryService.query(qo);
        model.addAttribute("result",pageInfo);
        //跟进类型

        return "/customerTraceHistory/list";
    }



    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    @RequiresPermissions(value = {"customerTraceHistory:saveOrupdate", "跟进客户新增/编辑"},logical = Logical.OR)
    public JsonResult saveOrupdate(CustomerTraceHistory customerTraceHistory){
        try {
            if (customerTraceHistory.getId() == null) {
                customerTraceHistoryService.save(customerTraceHistory);
            }else{
                customerTraceHistoryService.updateByPrimaryKey(customerTraceHistory);
            }
            return new JsonResult();
        }catch (Exception e){
            e.printStackTrace();
            return new JsonResult(false,"操作失败,请重新操作!");
        }
    }
}
